package bb.lanxing.util;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import com.umeng.socialize.net.dplus.CommonNetImpl;
import bb.lanxing.net.client.HttpProxy;
import java.io.File;
import no.nordicsemi.android.dfu.DfuBaseService;

public class ShareLogUtil {
    private static final String[][] MATCH_ARRAY = {new String[]{".3gp", "video/3gpp"}, new String[]{".apk", "application/vnd.android.package-archive"}, new String[]{".asf", "video/x-ms-asf"}, new String[]{".avi", "video/x-msvideo"}, new String[]{".bin", "application/octet-stream"}, new String[]{".bmp", "image/bmp"}, new String[]{".c", "text/plain"}, new String[]{".class", "application/octet-stream"}, new String[]{".conf", "text/plain"}, new String[]{".cpp", "text/plain"}, new String[]{".doc", "application/msword"}, new String[]{".exe", "application/octet-stream"}, new String[]{".gif", "image/gif"}, new String[]{".gtar", "application/x-gtar"}, new String[]{".gz", HttpProxy.MEDIA_TYPE_GZIP}, new String[]{".h", "text/plain"}, new String[]{".htm", "text/html"}, new String[]{".html", "text/html"}, new String[]{".jar", "application/java-archive"}, new String[]{".java", "text/plain"}, new String[]{".jpeg", "image/jpeg"}, new String[]{".jpg", "image/jpeg"}, new String[]{".js", "application/x-javascript"}, new String[]{".log", "text/plain"}, new String[]{".m3u", "audio/x-mpegurl"}, new String[]{".m4a", "audio/mp4a-latm"}, new String[]{".m4b", "audio/mp4a-latm"}, new String[]{".m4p", "audio/mp4a-latm"}, new String[]{".m4u", "video/vnd.mpegurl"}, new String[]{".m4v", "video/x-m4v"}, new String[]{".mov", "video/quicktime"}, new String[]{".mp2", "audio/x-mpeg"}, new String[]{".mp3", "audio/x-mpeg"}, new String[]{".mp4", "video/mp4"}, new String[]{".mpc", "application/vnd.mpohun.certificate"}, new String[]{".mpe", "video/mpeg"}, new String[]{".mpeg", "video/mpeg"}, new String[]{".mpg", "video/mpeg"}, new String[]{".mpg4", "video/mp4"}, new String[]{".mpga", "audio/mpeg"}, new String[]{".msg", "application/vnd.ms-outlook"}, new String[]{".ogg", "audio/ogg"}, new String[]{".pdf", "application/pdf"}, new String[]{".png", "image/png"}, new String[]{".pps", "application/vnd.ms-powerpoint"}, new String[]{".ppt", "application/vnd.ms-powerpoint"}, new String[]{".prop", "text/plain"}, new String[]{".rar", "application/x-rar-compressed"}, new String[]{".rc", "text/plain"}, new String[]{".rmvb", "audio/x-pn-realaudio"}, new String[]{".rtf", "application/rtf"}, new String[]{".sh", "text/plain"}, new String[]{".tar", "application/x-tar"}, new String[]{".tgz", "application/x-compressed"}, new String[]{".txt", "text/plain"}, new String[]{".log", "text/plain"}, new String[]{".wav", "audio/x-wav"}, new String[]{".wma", "audio/x-ms-wma"}, new String[]{".wmv", "audio/x-ms-wmv"}, new String[]{".wps", "application/vnd.ms-works"}, new String[]{".xml", "text/plain"}, new String[]{".z", "application/x-compress"}, new String[]{".zip", DfuBaseService.MIME_TYPE_ZIP}, new String[]{"", "*/*"}};
    public static String PACKAGE_NAME_QQ = "com.tencent.mobileqq";
    public static String PACKAGE_NAME_WX = "com.tencent.mm";

    public static void shareFile(Context context, File file, String str) {
        String str2;
        Uri fromFile;
        Intent intent = new Intent();
        intent.setPackage(str);
        intent.setAction("android.intent.action.SEND");
        int i = 0;
        while (true) {
            String[][] strArr = MATCH_ARRAY;
            if (i >= strArr.length) {
                str2 = "*/*";
                break;
            } else if (file.getAbsolutePath().contains(strArr[i][0])) {
                str2 = strArr[i][1];
                break;
            } else {
                i++;
            }
        }
        intent.setType(str2);
        Uri uri = null;
        if (file != null) {
            try {
                if (context.getApplicationInfo().targetSdkVersion >= 24 && Build.VERSION.SDK_INT >= 24) {
                    fromFile = FileProvider7.getUriForFile24(context, file);
                } else {
                    fromFile = Uri.fromFile(file);
                }
                uri = fromFile;
                intent.putExtra("android.intent.extra.STREAM", uri);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (SystemUtil.getVersionCode(context, "com.tencent.mm") > 7) {
            intent.setAction("android.intent.action.SEND");
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            intent.putExtra("android.intent.extra.STREAM", uri);
        }
        context.startActivity(Intent.createChooser(intent, "Share"));
    }
}
